package com.vois.jack.btmgr.blebase;

import android.os.Bundle;
import android.os.ParcelUuid;

import com.vois.jack.btmgr.common.IBtConstants;
import com.vois.jack.btmgr.util.Logger;

import java.util.Arrays;
import java.util.UUID;

public class DefaultBleDevice extends BleDevice {
    private Logger logger = Logger.getLogger(DefaultBleDevice.class);
    
    @Override
    public void onScanStateChanged(int state) {

    }

    @Override
    public void getValidationData() {

    }

    @Override
    public void onConnectStateChanged(int state, int reason) {
        logger.d( "onConnectStateChanged: " + state);
    }

    @Override
    public void onVerifying() {

    }

    @Override
    public void onReady() {
        logger.d( "onReady: ");
        UUID service = UUID.fromString("00001100-d102-11e1-9b23-00025b00a5a5");
        UUID response = UUID.fromString("00001102-d102-11e1-9b23-00025b00a5a5");
        BleAction bleAction = new BleAction();
        Bundle arg = new Bundle();
        bleAction.setCmd(BleAction.BleCmd.BLE_CMD_ENABLE_NOTIFICATION);
        arg.putParcelable(BleDeviceFsm.EXTRA_SERVICE_UUID, new ParcelUuid(service));
        arg.putParcelable(BleDeviceFsm.EXTRA_CHARACTERISTIC_UUID, new ParcelUuid(response));
        arg.putBoolean(BleDeviceFsm.EXTRA_ENABLE_VALUE, true);
        bleAction.setCmdArg(arg);
        bleAction.setCallback(new BleAction.BleActionCallback() {
            @Override
            public void onActionResult(int status, Bundle result) {
                logger.d( "onActionResult: status:" + status);
            }
        });

        getBleDeviceFsm().executeBleAction(bleAction);
    }

    @Override
    public void onError(int errorCause) {

    }

    @Override
    public void onCharacteristiChanged(UUID serviceUUID, UUID characteristicUUID, byte[] data) {
        logger.d( "onCharacteristiChanged: UUID:" + characteristicUUID.toString());
        logger.d( "onCharacteristiChanged: Value:" + Arrays.toString(data));
    }

    @Override
    public void onReliableWriteCompleted(int status) {

    }

    @Override
    public void onFsmStopped() {

    }

    @Override
    public String getDeviceModel() {
        return "Default Ble Model";
    }

    @Override
    public void setSeqID(String seqID) {

    }

    @Override
    public void getVendor() {

    }

    @Override
    public void getVersion() {

    }

    @Override
    public String getProtocolName() {
        return IBtConstants.PROTOCOL_VOIS;
    }
}
